package com.qiangesoft.blog.controller.web;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.qiangesoft.blog.common.mvc.PageQuery;
import com.qiangesoft.blog.common.mvc.PageResultVO;
import com.qiangesoft.blog.common.result.ResponseResult;
import com.qiangesoft.blog.core.pojo.dto.CommentDTO;
import com.qiangesoft.blog.core.pojo.vo.ArticleListVO;
import com.qiangesoft.blog.core.service.IBlogCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 评论接口
 *
 * @author qiange
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/api/comment")
@Api(tags = "评论接口")
@RequiredArgsConstructor
public class ApiBlogCommentController {

    private final IBlogCommentService commentService;

    @PostMapping(value = "/add")
    @SaCheckLogin
    @ApiOperation(value = "添加评论")
    public ResponseResult addComment(@RequestBody CommentDTO comment) {
        return commentService.addComment(comment);
    }

    @GetMapping(value = "/{articleId}")
    @ApiOperation(value = "查询文章评论")
    public PageResultVO<ArticleListVO> comments(@PathVariable Long articleId, PageQuery pageQuery) {
        return commentService.comments(articleId, pageQuery);
    }

    @RequestMapping(value = "/repliesByComId", method = RequestMethod.GET)
    @ApiOperation(value = "查询评论回复", httpMethod = "GET", response = ResponseResult.class, notes = "查询文章评论")
    public ResponseResult repliesByComId(Integer commentId) {
        return commentService.repliesByComId(commentId);
    }
}
